<?php

class Core_Model_Auth_LoginzaAdapter implements Zend_Auth_Adapter_Interface
{
    /**
     * Loginza token
     * @var string
     */
    private $_token;

    public function  __construct($token)
    {
        $this->_token = $token;
    }
    
    public function  authenticate()
    {
        $response = file_get_contents("http://loginza.ru/api/authinfo?token=" . $this->_token);
        $response = Zend_Json::decode($response);
        if (isset($response['error_type'])) {
            return new Zend_Auth_Result(
                Zend_Auth_Result::FAILURE,
                array(),
                array('Login failed')
            );
        } else {
            return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $response['identity']);
        }
    }
}